<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author <SONIA ZRIBI>
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Abstract class for models
 */
require_once 'ModelAbstract.php';

/**
 * 
 *
 * @package Application_Model
 * @subpackage Model
 * @author <SONIA ZRIBI>
 */
class Application_Model_ElementRapport extends Application_Model_ModelAbstract
{

    /**
     * Database var type int(11)
     *
     * @var int
     */
    protected $_IdelementRapport;

    /**
     * Database var type varchar(45)
     *
     * @var string
     */
    protected $_ElementRapportcol;

    /**
     * Database var type int(11)
     *
     * @var int
     */
    protected $_Idrapport;


    /**
     * Parent relation fk_element_rapport_rapport1
     *
     * @var Application_Model_Rapport
     */
    protected $_Rapport;


    /**
     * Dependent relation fk_datastat_element_rapport1
     * Type: One-to-Many relationship
     *
     * @var Application_Model_Datastat
     */
    protected $_Datastat;

    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'idelement_rapport'=>'IdelementRapport',
            'element_rapportcol'=>'ElementRapportcol',
            'idrapport'=>'Idrapport',
        ));

        $this->setParentList(array(
            'FkElementRapportRapport1'=> array(
                    'property' => 'Rapport',
                    'table_name' => 'Rapport',
                ),
        ));

        $this->setDependentList(array(
            'FkDatastatElementRapport1' => array(
                    'property' => 'Datastat',
                    'table_name' => 'Datastat',
                ),
        ));
    }

    /**
     * Sets column idelement_rapport
     *
     * @param int $data
     * @return Application_Model_ElementRapport
     */
    public function setIdelementRapport($data)
    {
        $this->_IdelementRapport = $data;
        return $this;
    }

    /**
     * Gets column idelement_rapport
     *
     * @return int
     */
    public function getIdelementRapport()
    {
        return $this->_IdelementRapport;
    }

    /**
     * Sets column element_rapportcol
     *
     * @param string $data
     * @return Application_Model_ElementRapport
     */
    public function setElementRapportcol($data)
    {
        $this->_ElementRapportcol = $data;
        return $this;
    }

    /**
     * Gets column element_rapportcol
     *
     * @return string
     */
    public function getElementRapportcol()
    {
        return $this->_ElementRapportcol;
    }

    /**
     * Sets column idrapport
     *
     * @param int $data
     * @return Application_Model_ElementRapport
     */
    public function setIdrapport($data)
    {
        $this->_Idrapport = $data;
        return $this;
    }

    /**
     * Gets column idrapport
     *
     * @return int
     */
    public function getIdrapport()
    {
        return $this->_Idrapport;
    }

    /**
     * Sets parent relation Idrapport
     *
     * @param Application_Model_Rapport $data
     * @return Application_Model_ElementRapport
     */
    public function setRapport(Application_Model_Rapport $data)
    {
        $this->_Rapport = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['idrapport'];
        }

        $this->setIdrapport($primary_key);

        return $this;
    }

    /**
     * Gets parent Idrapport
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Rapport
     */
    public function getRapport($load = true)
    {
        if ($this->_Rapport === null && $load) {
            $this->getMapper()->loadRelated('FkElementRapportRapport1', $this);
        }

        return $this->_Rapport;
    }

    /**
     * Sets dependent relations fk_datastat_element_rapport1
     *
     * @param array $data An array of Application_Model_Datastat
     * @return Application_Model_ElementRapport
     */
    public function setDatastat(array $data)
    {
        $this->_Datastat = array();

        foreach ($data as $object) {
            $this->addDatastat($object);
        }

        return $this;
    }

    /**
     * Sets dependent relations fk_datastat_element_rapport1
     *
     * @param Application_Model_Datastat $data
     * @return Application_Model_ElementRapport
     */
    public function addDatastat(Application_Model_Datastat $data)
    {
        $this->_Datastat[] = $data;
        return $this;
    }

    /**
     * Gets dependent fk_datastat_element_rapport1
     *
     * @param boolean $load Load the object if it is not already
     * @return array The array of Application_Model_Datastat
     */
    public function getDatastat($load = true)
    {
        if ($this->_Datastat === null && $load) {
            $this->getMapper()->loadRelated('FkDatastatElementRapport1', $this);
        }

        return $this->_Datastat;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_ElementRapport
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_ElementRapport());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_ElementRapport::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        if ($this->getIdelementRapport() === null) {
            throw new Exception('Primary Key does not contain a value');
        }

        return $this->getMapper()
                    ->getDbTable()
                    ->delete('idelement_rapport = ' .
                             $this->getMapper()
                                  ->getDbTable()
                                  ->getAdapter()
                                  ->quote($this->getIdelementRapport()));
    }
}
